<template>
    <div class="container">
        <img src="../../../assets/img/ss.jpg" alt="">
        <div class="refund" @click="handleDownload"></div>
        <div class="saveBtn" @click="handleConfirm"></div>
    </div>
  </template>
  
  <script>
  import { ref, reactive, getCurrentInstance, onMounted } from 'vue'
  import { useRouter, useRoute } from 'vue-router'
  import { showToast, showConfirmDialog, Swipe, SwipeItem, showDialog,Popup,Overlay} from 'vant'
  import api from '../api/index'
  import { Base64 } from 'js-base64';
  
  export default {
    component: {
      Swipe,
      SwipeItem,
      // Dialog,
    },
    setup() {
      onMounted(() => {
      })
      const router = useRouter()
      const route = useRoute()
      const checkedPay = ref('1')
      const amount ='79.9'
      const type = 'kala'
      const isPay =ref(false)
      const encryptionOperation= location.href.split("?")[1] && location.href.split("?")[1].split('&')[0] || ''
      const codeRe = route.query.code || ''
      const bxmid =  route.query.bxm_id  || '' // 变现猫
      const userkey =  route.query.userkey  || '' // xmod
      const bc_tag = route.query.bc_tag  || '' // 百川
      const nadkey =  route.query.nadkey  || '' // 秦禾
      const  qcjParamStr = route.query.qcjParamStr  || '' //高阳
      const plid = route.query.plid  || 0
      const operation =route.query.operation ? route.query.operation: (encryptionOperation && window.atob(encryptionOperation).split('=')[1] || '')
      const landingid = route.query.landingid  || '' //享点
      const a_oId = route.query.a_oId  || '' //推啊
      const company= route.query.company  || '' //公司
      const methods = {
        // 进页面就获取订单号存起来，支付链接
        init (name){
          const data =methods.montageParams()
          const { code,operation,company } = data
          const parmms ={
            code,
            operation,
            amount,
          }
          api.get('getOrderLink', { ...parmms }).then(res => {
            if (res.code === 200) {
              const { type, orderNo ,result} = res.data
              localStorage.setItem("params", JSON.stringify({
                outTradeNo:orderNo,
                amount: amount,
                operation,
                routeName: route.name,
                code,
                company
              }));
              location.href=result
              setTimeout(()=>{
                router.push({
                    path: '/resultWchat',
                    query: {
                    outTradeNo: orderNo,
                }
                })
              })
            } else {
              showToast(res.message)
            }
          }).catch(res=>{
            methods.init() 
          })
        },
        handleDownload() {
          router.push('/refund')
        },
        montageParams () {
          let code ='',other = 0 //唯一码 媒体类型 特殊字段
          if(!codeRe){
            if(bxmid){ 
              code =bxmid
            }else if(userkey){
              code =userkey
              other=plid
            } else if(bc_tag){
              code =bc_tag
            }else if(landingid){
              code =landingid
            }else if(qcjParamStr){
              code =qcjParamStr
            }else if(a_oId){
              code =a_oId
            }
            else{
              code =nadkey
            }
          }else{
            code = codeRe
          }
          const params = {
            code:code,
            operation:operation,
            company:company
          }
          return params
        },
        // 提交按钮
        handleConfirm () {
           methods.init()
        },
      }
  
      return {
        checkedPay,
        company,
        isPay,
        // codeRe,
        amount,
        ...methods,
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .container{
    position:relative;
    width:100%;
    height:100vh;
    background-color:#EC91AA;
    img{
        width:100%;
    }
    .refund{
        position: absolute;
        left: 0;
        top: 0.4rem;
        width: 30%;
        height: 0.27rem;
        background-color: #fff;
        opacity: 0;  
    }
    .saveBtn{
        position: absolute;
        width: 100%;
        height: 4rem;
        bottom: 0rem;
    }
  }
  </style>